#ifndef REDISMANAGER_H
#define REDISMANAGER_H

#include <hiredis.h>
#include <string>
#include <vector>
#include <map>

class RedisManager {
public:
    static RedisManager& instance();

    bool connect(const std::string& host = "127.0.0.1", int port = 6379);
    void disconnect();

    // 上传任务管理
    bool createUploadTask(long long userId, const std::string& fileMd5,
                          const std::string& fileName, long long fileSize,
                          const std::string& filePath);
    bool updateUploadProgress(long long userId, const std::string& fileMd5,
                              long long uploadedSize);
    bool pauseUploadTask(long long userId, const std::string& fileMd5);
    bool resumeUploadTask(long long userId, const std::string& fileMd5);
    bool removeUploadTask(long long userId, const std::string& fileMd5);
    bool getUploadTask(long long userId, const std::string& fileMd5,
                       std::map<std::string, std::string>& taskInfo);
    std::vector<std::map<std::string, std::string>> getUserUploadTasks(long long userId);

    // 通用Redis命令
    bool executeCommand(const std::string& cmd, std::string& reply);

private:
    RedisManager();
    ~RedisManager();

    redisContext* m_redisContext;
};

#endif // REDISMANAGER_H
